import time
import random

import redis
import requests

stop = True
i = 1
try:
    r = redis.Redis(host='127.0.0.1', port=6379, decode_responses=True)
    proxies = eval(r.get('proxies'))
    cookies = {
        '_ga': 'GA1.2.643054255.1638518444',
        '__tea_cookie_tokens_2608': '%257B%2522web_id%2522%253A%25227037383097776932387%2522%252C%2522ssid%2522%253A%2522e7516c20-9b14-4af9-b694-ae10b69c739c%2522%252C%2522user_unique_id%2522%253A%25227037383097776932387%2522%252C%2522timestamp%2522%253A1638518443906%257D',
        'store-region': 'cn-sh',
        'store-region-src': 'uid',
        'csrf_session_id': 'd4ee5235716aadc7d3eb1d22eb247fa9',
        '_tea_utm_cache_2608': '{%22utm_source%22:%22gold_browser_extension%22}',
        'passport_csrf_token': 'd05bced8fe39966871a1a2fd7bf34ce8',
        'passport_csrf_token_default': 'd05bced8fe39966871a1a2fd7bf34ce8',
        'n_mh': 'RrfypYxi68Zj9lln-cIaZoeMz55vmW8sLhCwLWvqqfs',
        'passport_auth_status': 'e422acb343d1f3a92b3311182508732d%2C',
        'passport_auth_status_ss': 'e422acb343d1f3a92b3311182508732d%2C',
        'sid_guard': 'cab08769111c2cab30bff9ad0482df26%7C1685326172%7C31536000%7CTue%2C+28-May-2024+02%3A09%3A32+GMT',
        'uid_tt': '2e090e9d5b18ffcfee01a3840c53d350',
        'uid_tt_ss': '2e090e9d5b18ffcfee01a3840c53d350',
        'sid_tt': 'cab08769111c2cab30bff9ad0482df26',
        'sessionid': 'cab08769111c2cab30bff9ad0482df26',
        'sessionid_ss': 'cab08769111c2cab30bff9ad0482df26',
        'sid_ucp_v1': '1.0.0-KGYzMTRkNzUxOGZlZDFmYzQ0NGU1NmJmN2Y1NjUzODEwNjBlMjNlNGYKFgiuyICetIxhENyS0KMGGLAUOAJA8QcaAmxmIiBjYWIwODc2OTExMWMyY2FiMzBiZmY5YWQwNDgyZGYyNg',
        'ssid_ucp_v1': '1.0.0-KGYzMTRkNzUxOGZlZDFmYzQ0NGU1NmJmN2Y1NjUzODEwNjBlMjNlNGYKFgiuyICetIxhENyS0KMGGLAUOAJA8QcaAmxmIiBjYWIwODc2OTExMWMyY2FiMzBiZmY5YWQwNDgyZGYyNg',
        'msToken': 'zTJFKlqITAd27UASdw4bylGMGKPurJXJk-mNctNPf1I3843-ygcmpFxsdTp5Ab48nJMdbPGD25qs6KHSV6zWa8rIDmTdpNGGLGR4xhIB7lWt',
    }

    headers = {
        'authority': 'api.juejin.cn',
        'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="96", "Google Chrome";v="96"',
        'sec-ch-ua-mobile': '?0',
        'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36',
        'sec-ch-ua-platform': '"macOS"',
        'content-type': 'application/json',
        'accept': '*/*',
        'origin': 'https://juejin.cn',
        'sec-fetch-site': 'same-site',
        'sec-fetch-mode': 'cors',
        'sec-fetch-dest': 'empty',
        'referer': 'https://juejin.cn/',
        'accept-language': 'zh-CN,zh;q=0.9',
        # 'cookie': '_ga=GA1.2.643054255.1638518444; __tea_cookie_tokens_2608=%257B%2522web_id%2522%253A%25227037383097776932387%2522%252C%2522ssid%2522%253A%2522e7516c20-9b14-4af9-b694-ae10b69c739c%2522%252C%2522user_unique_id%2522%253A%25227037383097776932387%2522%252C%2522timestamp%2522%253A1638518443906%257D; store-region=cn-sh; store-region-src=uid; csrf_session_id=d4ee5235716aadc7d3eb1d22eb247fa9; _tea_utm_cache_2608={%22utm_source%22:%22gold_browser_extension%22}; passport_csrf_token=d05bced8fe39966871a1a2fd7bf34ce8; passport_csrf_token_default=d05bced8fe39966871a1a2fd7bf34ce8; n_mh=RrfypYxi68Zj9lln-cIaZoeMz55vmW8sLhCwLWvqqfs; passport_auth_status=e422acb343d1f3a92b3311182508732d%2C; passport_auth_status_ss=e422acb343d1f3a92b3311182508732d%2C; sid_guard=cab08769111c2cab30bff9ad0482df26%7C1685326172%7C31536000%7CTue%2C+28-May-2024+02%3A09%3A32+GMT; uid_tt=2e090e9d5b18ffcfee01a3840c53d350; uid_tt_ss=2e090e9d5b18ffcfee01a3840c53d350; sid_tt=cab08769111c2cab30bff9ad0482df26; sessionid=cab08769111c2cab30bff9ad0482df26; sessionid_ss=cab08769111c2cab30bff9ad0482df26; sid_ucp_v1=1.0.0-KGYzMTRkNzUxOGZlZDFmYzQ0NGU1NmJmN2Y1NjUzODEwNjBlMjNlNGYKFgiuyICetIxhENyS0KMGGLAUOAJA8QcaAmxmIiBjYWIwODc2OTExMWMyY2FiMzBiZmY5YWQwNDgyZGYyNg; ssid_ucp_v1=1.0.0-KGYzMTRkNzUxOGZlZDFmYzQ0NGU1NmJmN2Y1NjUzODEwNjBlMjNlNGYKFgiuyICetIxhENyS0KMGGLAUOAJA8QcaAmxmIiBjYWIwODc2OTExMWMyY2FiMzBiZmY5YWQwNDgyZGYyNg; msToken=zTJFKlqITAd27UASdw4bylGMGKPurJXJk-mNctNPf1I3843-ygcmpFxsdTp5Ab48nJMdbPGD25qs6KHSV6zWa8rIDmTdpNGGLGR4xhIB7lWt',
    }
    while stop:
        index = random.randint(0, len(proxies) - 1)
        time.sleep(3)
        requests.packages.urllib3.disable_warnings()

        response = requests.get('https://juejin.cn/post/7249664547219603511', proxies=proxies[index], cookies=cookies, headers=headers, verify=False)
        index = random.randint(0, len(proxies) - 1)
        # time.sleep(5)
        # print(response)
        # index = random.randint(0, len(proxies) - 1)
        # response = requests.get('https://juejin.cn/post/7237540467427590199', proxies=proxies[index],  cookies=cookies, headers=headers,
        #                         verify=False)
        # index = random.randint(0, len(proxies) - 1)
        # time.sleep(5)
        # print(response)
        #
        # response = requests.get('https://juejin.cn/post/7237046997734883386', proxies=proxies[index],  cookies=cookies, headers=headers,
        #                         verify=False)
        # index = random.randint(0, len(proxies) - 1)
        # time.sleep(5)
        # print(response)
        # response = requests.get('https://juejin.cn/post/7237001554083266617', proxies=proxies[index], cookies=cookies, headers=headers,
        #                         verify=False)
        # index = random.randint(0, len(proxies) - 1)
        # time.sleep(5)
        # response = requests.get('https://juejin.cn/post/7231858374828228665', proxies=proxies[index], cookies=cookies, headers=headers,
        #                         verify=False)
        # index = random.randint(0, len(proxies) - 1)
        # time.sleep(5)
        print(response)
        i = i+1
        print(i)



except Exception as e:
    print('except:', e)
finally:
    stop = True
